<template>
<!-- 投保单 列表页 -->
    <div>
        <el-form :inline="true"  class="demo-form-inline">
            <el-form-item label="被保险人姓名">
                <el-input v-model="user" placeholder="被保险人姓名"></el-input>
            </el-form-item>
           
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>
         <el-table v-if="tableData3.length>0" :data="tableData3" border style="width: 100%" >
            <el-table-column prop="SALESDETAIL.SALESDETAIL_ID" label="投保单号" width="180">
            </el-table-column>           
            <el-table-column prop="SALESDETAIL.SALESDETAIL_SALESTIME" label="销售时间" width="180" :formatter="localDataFomatter">
            </el-table-column>
            <el-table-column prop="CUSTOM.CUSTOM_NAME" label="被保险人姓名" width="180">
            </el-table-column>
            <el-table-column prop="SALESDETAIL.PRODUCE_NAME" label="产品类型" width="200">
            </el-table-column>
            <el-table-column prop="SALESDETAIL.SALESDETAIL_OLD" label="投保年龄" width="200">
            </el-table-column>
            <el-table-column prop="SALESDETAIL.SALESDETAIL_MONEY" label="保费金额" width="200">
            </el-table-column>
            <el-table-column prop="SALESDETAIL.SALESDETAIL_ADDMONEY" label="增额保费" width="200">
            </el-table-column>

            <el-table-column label="操作" width="200" fixed="right">
                <template scope="scope">
                    <el-button type="text" size="media" v-if="type=='退保申请'" @click="goAskForm(scope.row)">
                        <i class="el-icon-view"> 退保</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='退保审核'" @click="goCheck(scope.row)">
                        <i class="el-icon-view"> 审核</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='退保确认'" @click="goEnsure(scope.row)">
                        <i class="el-icon-view"> 确认</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='退保修改'" @click="goChange(scope.row)">
                        <i class="el-icon-view"> 修改</i>
                    </el-button>
                    <!-- <el-button type="text" size="media" v-if="type=='查看结果'" @click="goResult(scope.row)">
                        <i class="el-icon-view"> 查看结果</i>
                    </el-button> -->

                </template>
            </el-table-column>

        </el-table>
        <div class="block">
            <el-pagination @current-change="handleCurrentChange" :current-page="currentPage1" :page-size="10" layout="total, prev, pager, next" :total="pagecount">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import api from "@/js/api";
import { mapState } from "vuex";
export default {
  data() {
    return {
      user: "",
      pagecount: 0,
      currentPage1: 1,
      tableData3: []
    };
  },
  props: {
    id: {
      type: {
        type: String,
        default: ""
      }
    },
    type: {
      type: String,
      default: "待沟通"
    }
  },
  computed: mapState({
    saleDetail: state => state.SealDetail.model
  }),
  methods: {
    localDataFomatter(row, column, cellValue) {
      cellValue = cellValue + "Z";
      var data = new Date(cellValue);
      var dataString =
        data.getFullYear() +
        "/" +
        (data.getMonth() + 1 >= 10
          ? data.getMonth() + 1
          : "0" + (data.getMonth() + 1)) +
        "/" +
        (data.getDate() >= 10 ? data.getDate() : "0" + data.getDate()) +
        " " +
        (data.getHours() >= 10 ? data.getHours() : "0" + data.getHours()) +
        ":" +
        (data.getMinutes() >= 10 ? data.getMinutes() : "0" + data.getMinutes());
      return dataString;
    },
    goAskForm(obj) {
      //传递数据为对象 所以更改后会改变列表数据 1.深拷贝2.关闭时，重新获取数据； 采用了第二种(后期可更换第一种，减少请求)
      var cloneObj = JSON.parse(JSON.stringify(obj));
        cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME=cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME+"Z";
        cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME=cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME+"Z";
         cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME=cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME+"Z";
      this.$emit("goAskForm", {
        SALESDETAIL_ID: cloneObj.SALESDETAIL.SALESDETAIL_ID,
        SALESDETAIL_INSURANCENUMBER:
          cloneObj.SALESDETAIL.SALESDETAIL_INSURANCENUMBER
      });
      this.$store.commit("changer", cloneObj.SALESDETAIL);
      this.saleDetail.CUSTOM = cloneObj.CUSTOM;
      this.saleDetail.RELATIONPEOPLEs = cloneObj.SALESDETAIL.RELATIONPEOPLEs;
      this.saleDetail.QUESTION = cloneObj.SALESDETAIL.QUESTION;
    },
    handleCurrentChange(val) {
      this.currentPage1 = val;
      this.getDate();
    },
    goCheck(obj) {
      var cloneObj = JSON.parse(JSON.stringify(obj));      
       cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME=cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME+"Z";
        cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME=cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME+"Z";
         cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME=cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME+"Z";
      this.$emit("goCheck", {
        SALESDETAIL_ID: cloneObj.SALESDETAIL.SALESDETAIL_ID,
        SALESDETAIL_INSURANCENUMBER:
          cloneObj.SALESDETAIL.SALESDETAIL_INSURANCENUMBER
      });
      this.$store.commit("changer", cloneObj.SALESDETAIL);
      this.saleDetail.CUSTOM = cloneObj.CUSTOM;
      this.saleDetail.RELATIONPEOPLEs = cloneObj.SALESDETAIL.RELATIONPEOPLEs;
      this.saleDetail.QUESTION = cloneObj.SALESDETAIL.QUESTION;
    },
    goEnsure(obj) {
      var cloneObj = JSON.parse(JSON.stringify(obj));
        cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME=cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME+"Z";
        cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME=cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME+"Z";
         cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME=cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME+"Z";
      this.$emit("goEnsure", {
        SALESDETAIL_ID: cloneObj.SALESDETAIL.SALESDETAIL_ID,
        SALESDETAIL_INSURANCENUMBER:
          cloneObj.SALESDETAIL.SALESDETAIL_INSURANCENUMBER
      });
      this.$store.commit("changer", cloneObj.SALESDETAIL);
      this.saleDetail.CUSTOM = cloneObj.CUSTOM;
      this.saleDetail.RELATIONPEOPLEs = cloneObj.SALESDETAIL.RELATIONPEOPLEs;
      this.saleDetail.QUESTION = cloneObj.SALESDETAIL.QUESTION;
    },
    goChange(obj) {
      var cloneObj = JSON.parse(JSON.stringify(obj));
        cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME=cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME+"Z";
        cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME=cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME+"Z";
         cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME=cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME+"Z";
      this.$emit("goChange", {
        SALESDETAIL_ID: cloneObj.SALESDETAIL.SALESDETAIL_ID,
        SALESDETAIL_INSURANCENUMBER:
          cloneObj.SALESDETAIL.SALESDETAIL_INSURANCENUMBER
      });
      this.$store.commit("changer", cloneObj.SALESDETAIL);
      this.saleDetail.CUSTOM = cloneObj.CUSTOM;
      this.saleDetail.RELATIONPEOPLEs = cloneObj.SALESDETAIL.RELATIONPEOPLEs;
      this.saleDetail.QUESTION = cloneObj.SALESDETAIL.QUESTION;
    },
    goResult(obj) {
      var cloneObj = JSON.parse(JSON.stringify(obj));
        cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME=cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME+"Z";
        cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME=cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME+"Z";
         cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME=cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME+"Z";
      this.$emit("goResult", {
        SALESDETAIL_ID: cloneObj.SALESDETAIL.SALESDETAIL_ID,
        SALESDETAIL_INSURANCENUMBER:
          cloneObj.SALESDETAIL.SALESDETAIL_INSURANCENUMBER
      });
      this.$store.commit("changer", cloneObj.SALESDETAIL);
      this.saleDetail.CUSTOM = cloneObj.CUSTOM;
      this.saleDetail.RELATIONPEOPLEs = cloneObj.SALESDETAIL.RELATIONPEOPLEs;
      this.saleDetail.QUESTION = cloneObj.SALESDETAIL.QUESTION;
    },
    onSubmit() {
      this.getDate();
    },
    getDate() {
      var data = {
        state: "",
        pageSize: 10,
        pageIndex: this.currentPage1,
        name: ""
      };
      //购买完成 需退保审核 需退保修改 需退保确认
      switch (this.type) {
        case "退保申请":
          data.state = "购买完成";
          break;
        case "退保审核":
          data.state = "需退保审核";
          break;
        case "退保修改":
          data.state = "需退保修改";
          break;
        case "退保确认":
          data.state = "需退保确认";
          break;
      }
      // console.log(this.user == "");
      let that = this;
      if (this.user != undefined && this.user != "") {
        data.name = this.user;
        api.SaledetailSelectByName(that, data, function(msg) {
          that.tableData3 = msg.Result;
          that.pagecount = msg.ListCount;
        });
      } else {
        api.SaledetailSelect(that, data, function(msg) {
          that.tableData3 = msg.Result;
          that.pagecount = msg.ListCount;
        });
      }
    }
  },
  created() {
    this.getDate();
    this.$store.commit("changer", {});
  }
};
</script>
